﻿using System.Linq;
using Calhoon.MarkupParser;
using System.Collections.ObjectModel;

namespace WhiteListExample
{
	public class WhiteListParser : Parser
	{
		private WhiteListParser() : base(new ParseState()) {

		}

		public static string Filter(string input) {
			WhiteListParser parser = new WhiteListParser();
			parser.Source = input;

			Collection<PrimitiveTag> tags = parser.Parse();

			WhiteListTagConverter converter = new WhiteListTagConverter();
			DocumentHierarchyCreator hierarchyCreator = new DocumentHierarchyCreator();

			HierarchyNode root = hierarchyCreator.BuildHierarchy(tags.ToArray<PrimitiveTag>(), converter);

			return root.Render();
		}
	}
}
